package sample;

import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;


import java.io.File;
import java.io.IOException;


public class TopPart {
    /**
     * 顶部
     * @return
     */
   public static String topUrl="";
   public static boolean bl=false;
   public static void TopUrl(String url){
       String [] srcs = url.split("\\"+"\\");

       for(int i=0;i<srcs.length;i++){
           if(i==0){
               topUrl=srcs[i];
           }else if(i==srcs.length-1){
               topUrl=topUrl+"";
               if(srcs[i].equals("白富美密码锁")){
                   bl=true;
               }else{
                   bl=false;
               }
           }else{
               topUrl=topUrl+"\\"+srcs[i];
           }

       }

   }


   public HBox anchorPaneTopPart()throws Exception{
       HBox hBox = new HBox();
        TopUrl(BeautyMain.themeURL);


       //vivo_window_statusbar_bg_color
       //E:\第二阶段素材\白富美密码锁\vivo


       String url = BeautyMain.themeURL+"\\vivo\\theme_values.xml";
       String param = "vivo_window_statusbar_bg_color";
       String colorFont =   DOM4JTest.attrValue(url,param);
       String style = "-fx-background-color:"+colorFont+"";
       hBox.setStyle( "-fx-background-color:"+ "rgba("+colorFont+")");//填充颜色属性

       HBox anchorPane = new HBox();
        hBox.setPrefWidth(480);
        hBox.setPrefHeight(28);
        anchorPane.getChildren().addAll(left1(),center1(),right1());

       // hBox.setStyle("-fx-background-color: blueviolet");
        hBox.getChildren().addAll(anchorPane);
       return hBox;
   }
   public HBox anchorPaneTopPart2()throws Exception{
        HBox hBox = new HBox();


        //hBox.setStyle("-fx-background-color: #B9DEE7");//填充颜色属性
        HBox anchorPane = new HBox();
        hBox.setPrefWidth(480);
        hBox.setPrefHeight(28);

        if(bl){
            anchorPane.getChildren().addAll(left2(),center2(),right2());
        }else{
            anchorPane.getChildren().addAll(left1(),center1(),right1());
            System.out.println();
        }
       System.out.println("bl===="+bl);



        hBox.getChildren().addAll(anchorPane);
        return hBox;
    }



    /**
     * 4G和信号
     * @return
     * @throws Exception
     */
   public HBox left1() throws Exception{

       HBox hBox = new HBox();
       HBox leftAll = new HBox();
       HBox lefth1 = new HBox();
       HBox lefth2 = new HBox();
       DOM4JTest dom4JTest = new DOM4JTest();
       String src = BeautyMain.themeURL+"\\vivo\\theme_values.xml";//路径
       String attrName = "vivo_window_statusbar_bg_color";
       dom4JTest.attrValue(src,attrName);


       ImageView imageView = new ImageView();
       imageView.setFitWidth(17);
       imageView.setFitHeight(14);


       File file =  new File(topUrl+"\\titlepreview\\signal_black.png");

       String localImage = file.toURI().toURL().toString();
       Image image = new Image(localImage);
       imageView.setImage(image);


       file = new File(BeautyMain.themeURL+"\\com.android.systemui\\vivo_signal4_small_4_color.png");

       localImage = file.toURI().toURL().toString();
       Image image1 = new Image(localImage);
       ImageView imageView1 = new ImageView();
       imageView1.setImage(image1);
       imageView1.setFitWidth(34);
       imageView1.setFitHeight(16);
       lefth1.getChildren().addAll(imageView);
       lefth1.setPadding(new Insets(3,0,0,0));
       lefth2.getChildren().add(imageView1);
       //lefth2.setPadding(new Insets(3,0,15,0));
       leftAll.getChildren().addAll(lefth1,lefth2);
       leftAll.setPadding(new Insets(3,0,0,16));
       Label label = new Label("无SIM");
       boolean bl =  TopPart.judeFileExists(file);
       label.setTextFill(Color.BLACK);
       label.setPadding(new Insets(7,0,0,10));
       if(bl){
           hBox.getChildren().add(leftAll);
       }else{
           hBox.getChildren().addAll(label);
           hBox.setPadding(new Insets(0,0,0,5));

       }
       //hBox.setStyle("-fx-background-color: red");
       SetSize.SetWidthSize(hBox,67);



       return hBox;
   }
   public HBox left2() throws Exception{
        HBox hBox = new HBox();
        HBox leftAll = new HBox();
        HBox lefth1 = new HBox();
        HBox lefth2 = new HBox();

        ImageView imageView = new ImageView();
        imageView.setFitWidth(17);
        imageView.setFitHeight(14);


        File file =  new File(topUrl+"\\titlepreview\\signal_light.png");
        String localImage = file.toURI().toURL().toString();
        Image image = new Image(localImage);
        imageView.setImage(image);


        file = new File(BeautyMain.themeURL+"\\com.android.systemui\\vivo_signal_small_4_white.png");
        localImage = file.toURI().toURL().toString();
        Image image1 = new Image(localImage);
        ImageView imageView1 = new ImageView();
        imageView1.setImage(image1);
        imageView1.setFitWidth(34);
        imageView1.setFitHeight(16);
        lefth1.getChildren().addAll(imageView);
        lefth1.setPadding(new Insets(3,0,0,0));
        lefth2.getChildren().add(imageView1);
        //lefth2.setPadding(new Insets(3,0,15,0));
        leftAll.getChildren().addAll(lefth1,lefth2);
        leftAll.setPadding(new Insets(3,0,0,16));


//       hBox.setPrefWidth(480);
//       hBox.setPrefHeight(28);
       Label label = new Label("无SIM");
       boolean bl =  TopPart.judeFileExists(file);
       label.setTextFill(Color.BLACK);
       label.setPadding(new Insets(7,0,0,10));
       if(bl){
           hBox.getChildren().add(leftAll);
       }else{
           hBox.getChildren().addAll(label);
       }
       SetSize.SetWidthSize(hBox,67);
        return hBox;
    }

    /**
     * 时间
     * @return
     * @throws Exception
     */
   public HBox center1() throws Exception{
       HBox hBox = new HBox();
       File file = new File(topUrl+"\\titlepreview\\time_black.png");
       String localImage = file.toURI().toURL().toString();
       ImageView imageView = new ImageView();
       imageView.setFitWidth(44);
       imageView.setFitHeight(13);
       Image image = new Image(localImage);
       imageView.setImage(image);
       hBox.getChildren().add(imageView);
       hBox.setPadding(new Insets(10,0,0,145));
       return hBox;
   }
   public HBox center2() throws Exception{
        HBox hBox = new HBox();
        File file = new File(topUrl+"\\titlepreview\\time_light.png");
        String localImage = file.toURI().toURL().toString();
        ImageView imageView = new ImageView();
        imageView.setFitWidth(44);
        imageView.setFitHeight(13);
        Image image = new Image(localImage);
        imageView.setImage(image);
        hBox.getChildren().add(imageView);
        hBox.setPadding(new Insets(10,0,0,145));
        return hBox;
    }

    /**
     * wifi和电池
     * @return
     * @throws Exception
     */
   public HBox right1()throws Exception{
       HBox hBox = new HBox();
       HBox wifiHBox = new HBox();
       HBox batterHBox = new HBox();
       File file = new File(topUrl+"\\titlepreview\\wifi_black.png");
       String localImage = file.toURI().toURL().toString();
       ImageView imageView = new ImageView();
       Image image = new Image(localImage);
       imageView.setFitWidth(17);
       imageView.setFitHeight(14);
       imageView.setImage(image);
       wifiHBox.setPadding(new Insets(8,2,0,0));
       wifiHBox.getChildren().addAll(imageView);



        file = new File(BeautyMain.themeURL+"\\com.android.systemui\\vivo_battery_20_19_color.png");
        localImage = file.toURI().toURL().toString();
        Image image1 = new Image(localImage);
        ImageView imageView1 = new ImageView();
        imageView1.setImage(image1);
         batterHBox.getChildren().addAll(imageView1);
       if(image1.getWidth()==74){
           imageView1.setFitHeight(15);
           imageView1.setFitWidth(36);
           batterHBox.setMargin(imageView1,new Insets(7,0,0,0));
           //imageView1.setFitWidth();
       }else{
           imageView1.setFitWidth(36);
           imageView1.setFitHeight(31);
       }

        hBox.setPadding(new Insets(0,10,0,159));
       hBox.getChildren().addAll(wifiHBox,batterHBox);
       return hBox;
   }
   public HBox right2()throws Exception{
        HBox hBox = new HBox();
        HBox wifiHBox = new HBox();
        HBox batterHBox = new HBox();
        File file = new File(topUrl+"\\titlepreview\\wifi_light.png");
        String localImage = file.toURI().toURL().toString();
        ImageView imageView = new ImageView();
        Image image = new Image(localImage);
        imageView.setFitWidth(17);
        imageView.setFitHeight(14);
        imageView.setImage(image);
        wifiHBox.setPadding(new Insets(8,2,0,0));
        wifiHBox.getChildren().addAll(imageView);



        file = new File(BeautyMain.themeURL+"\\com.android.systemui\\vivo_battery_20_19_white.png");
        localImage = file.toURI().toURL().toString();
        Image image1 = new Image(localImage);
       ImageView imageView1 = new ImageView();

        if(image1.getWidth()==74.0){
            imageView1.setFitHeight(15);
            imageView1.setFitWidth(30);
            //imageView1.setFitWidth();
        }else{
            imageView1.setFitWidth(36);
            imageView1.setFitHeight(31);
        }


        imageView1.setImage(image1);

        batterHBox.getChildren().addAll(imageView1);
        hBox.setPadding(new Insets(0,10,0,160));
        hBox.getChildren().addAll(wifiHBox,batterHBox);
        return hBox;
    }
   public static boolean judeFileExists(File file) {

        return file.exists();

            }





}
